package com.dayaokeji.rhythmschoolstudent.client.home.course.services

import com.dayaokeji.rhythmschoolstudent.utils.ServerCallback
import com.dayaokeji.server_api.ApiUtils
import com.dayaokeji.server_api.ServerResponse
import com.dayaokeji.server_api.api.CourseScoringApi
import com.dayaokeji.server_api.domain.CourseTemplate
import com.dayaokeji.server_api.domain.ScoringRankCourse
import io.reactivex.Observable

/**
 *********************************************************************
 **  Created by Fei wo on 2018-12-4
 *********************************************************************
 **  version 1.0
 *********************************************************************
 **  Copyright (C) dayaokeji.com 2018 -- 2020 All rights reserved.
 *********************************************************************
 ** 课程相关服务
 *********************************************************************
 */
object CourseService {

    /**
     * 获取课程模板数据
     */
    fun findTemplateCourseAll(termDate: Array<String>, uid: String): Observable<List<CourseTemplate>> = Observable.create { n ->
        ApiUtils.getApi(CourseScoringApi::class.java).findTemplateCourses(termDate[0],termDate[1],uid).enqueue(object : ServerCallback<List<CourseTemplate>>() {
            override fun onResponse(success: Boolean, response: ServerResponse<List<CourseTemplate>>?) {
                if (success) {
                    response?.let {
                        n.onNext(it.body)
                    }
                }
            }
        })
    }

    /**
     * 根据模板ID获取每节课
     */
    fun findCourseAllByTempId(tmpId: Int,uid: String): Observable<List<ScoringRankCourse>> = Observable.create { n ->
        ApiUtils.getApi(CourseScoringApi::class.java).findCoursesByTempId(tmpId,uid).enqueue(object : ServerCallback<List<ScoringRankCourse>>() {
            override fun onResponse(success: Boolean, response: ServerResponse<List<ScoringRankCourse>>?) {
                if (success) {
                    response?.let {
                        n.onNext(it.body)
                    }
                }
            }
        })
    }
}